<template>
  <div class="mod-user">
    <el-button plain disabled>物业账套</el-button>
    <el-button plain @click="WithdrawalRecord">到家账套</el-button>
    <el-form :inline="true" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <el-form-item>
          <div class="balance-searchMoney">
            法人公司账套编码
            <el-input class="input" v-model="legalAccountCode" placeholder="请输入法人公司账套编码"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            法人公司名称
            <el-input class="input" v-model="legalCompanyName" placeholder="请输入法人公司名称"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            状态
            <el-select v-model="isEnable" filterable placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="primary" @click="demand">查询</el-button>
        <el-button type="primary" @click="empty">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <div style="
        background-color: #fff;
        margin-top: 16px;
        border-radius: 6px;
        padding: 16px;
      ">
      <div style="
          display: flex;
          justify-content: flex-end;
          margin-bottom: 10px;
          box-sizing: border-box;
        ">
        <el-button type="primary" size="medium" @click="getDataListTwo">同步账套设置</el-button>
        <el-button type="primary" size="medium" @click="exportExcel()">导出Excel</el-button>
      </div>

      <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color" style="width: 100%;">
        <template slot="empty">
          <img class="machine" src="../../assets/img/machine.svg" alt="" />
          <div style="font-size: 14px; text-align: center">暂无数据</div>
        </template>
        <!-- <el-table-column prop="projectCode" header-align="center" align="center" label="项目编码">
        </el-table-column>
        <el-table-column prop="projectName" header-align="center" align="center" label="项目名称">
        </el-table-column> -->
        <el-table-column prop="legalAccountCode" header-align="center" align="center" label="法人公司账套编码">
        </el-table-column>
        <el-table-column prop="legalCompanyName" header-align="center" align="center" label="法人公司名称">
        </el-table-column>
        <!-- <el-table-column prop="" header-align="center" align="center" label="归属城市">
        </el-table-column> -->
        <!-- <el-table-column prop="bankAccountCode" header-align="center" align="center" label="银行账户编码">
        </el-table-column>
        <el-table-column prop="bankAccountName" header-align="center" align="center" label="银行账户名称">
        </el-table-column> -->
        <el-table-column fixed="right" header-align="center" align="center" label="状态">
          <template slot-scope="scope">
            <div v-if="(scope.row.isEnable == 1)">有效</div>
            <div v-if="(scope.row.isEnable == 0)">无效</div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" label="操作">
          <template slot-scope="scope">
            <el-button v-if="(scope.row.isEnable == 1)" type="text" size="small" :data-id="scope.row.id" @click="addOrUpdateHandle(scope.row)">查看详情</el-button>
            <el-button v-if="(scope.row.isEnable == 1)" type="text" size="small" :data-id="scope.row.id" @click="open(scope.row)">停用</el-button>
            <el-button v-if="(scope.row.isEnable == 0)" type="text" size="small" :data-id="scope.row.id" @click="open(scope.row)">启用</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './packageManagement-add-or-upate.vue'
export default {
  data () {
    return {
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      value1: '',
      type: 1,
      len: '',
      isShowAll: true,
      isEnable: '',
      userCode: '',
      legalAccountCode: '',
      legalCompanyName: '',
      options: [
        {
          value: "0",
          label: "无效",
        },
        {
          value: "1",
          label: "有效",
        }
      ],
    }
  },
  components: {
    AddOrUpdate
  },
  activated () {
    this.userCode = localStorage.getItem('userCode')
    this.getDataList()
  },
  methods: {
    // 同步账套设置
    getDataListTwo () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl(
          'cassadmin/v1/companyAccount/synchronizationAccount'
        ),
        method: 'post',
        data: this.$http.adornData({})
      }).then(({ data }) => {
        if (data.success == 1) {
          this.getDataList()
        } else {
          this.getDataList()
        }
        this.dataListLoading = false
      })
    },
    open (e) {
      var that = this
      var text = ''
      var number = ''
      if (e.isEnable == 0) {
        text = '启用'
        number = '1'
      } else {
        text = '停用'
        number = '0'
      }
      this.$confirm('是否' + text, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl(
              'cassadmin/v1/companyAccount/updateEnableStatus'
            ),
            method: 'post',
            data: this.$http.adornData({
              bankAccountCode: '',
              enableType: 'detail',
              isEnable: number,
              legalAccountCode: e.legalAccountCode
            })
          }).then(({ data }) => {
            if (data.success == 1) {
              this.$message({
                type: 'success',
                message: '成功!'
              })
              that.getDataList()
            } else {
              this.$message.error(data.errorMsg)
            }
            this.dataListLoading = false
          })
        })
        .catch(() => { })
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl(
          'cassadmin/v1/legalPersonDetail/getLegalAccountByPage'
        ),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          isShowAll: 'true',
          type: 1,
          isEnable: this.isEnable,
          legalAccountCode: this.legalAccountCode,
          legalCompanyName: this.legalCompanyName
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data)
          this.dataList = data.data.list
          this.totalPage = data.data.total
          this.dataListLoading = false
        } else {
          this.dataList = []
          this.totalPage = 0
        }
      })
    },
    //清空
    empty () {
      this.legalAccountCode = ''
      this.legalCompanyName = ''
      this.isEnable = ''
      this.getDataList()
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl(
          'cassadmin/v1/legalPersonDetail/getLegalAccountByPage'
        ),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          isShowAll: 'true',
          type: 1,
          legalAccountCode: this.legalAccountCode,
          legalCompanyName: this.legalCompanyName
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data)
          this.dataList = data.data.list
          this.len = data.data.list.length
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl(
          'cassadmin/v1/legalPersonDetail/getLegalAccountByPage'
        ),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          isShowAll: 'true',
          type: 1,
          isEnable: this.isEnable,
          legalAccountCode: this.legalAccountCode,
          legalCompanyName: this.legalCompanyName
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data)
          this.dataList = data.data.list
          this.len = data.data.list.length
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl(
          'cassadmin/v1/legalPersonDetail/getLegalAccountByPage'
        ),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          isShowAll: 'true',
          type: 1,
          isEnable: this.isEnable,
          legalAccountCode: this.legalAccountCode,
          legalCompanyName: this.legalCompanyName
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data)
          this.dataList = data.data.list
          this.len = data.data.list.length
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 查看详情
    addOrUpdateHandle (legalAccountCode) {
      console.log(legalAccountCode)
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(legalAccountCode)
      })
    },
    // 导出excel
    exportExcel () {
      window.location.href =
        `https://api.xstarlife.com/cassadmin/v1/legalPersonDetail/legalAccountExport?page=1&size=1000&legalAccountCode=${this.legalAccountCode}&legalCompanyName=${this.legalCompanyName}&isShowAll=${this.isShowAll}&type=${this.type}&isEnable=${this.isEnable}`
    },
    //到家账套
    WithdrawalRecord () {
      this.$router.push({
        name: `totalFinance-packageManagementlist`,
      });
    },
  }
}
</script>
<style scoped >
.seacrhMoney {
  display: flex;
}
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
</style>

